﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;


namespace WindowsFormsApplication1
{
    public partial class mainForm : Form
    {
        public mainForm()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            /*if(FIRSTRUN){
                Form firstrun = new firstrunform;
                firstrun.Show();
            }*/
        }

        /*private void btnBerechnen_Click(object sender, EventArgs e)
        {
                double zahl1, zahl2;
                string zeichen;

                string[] tmp = new string[5];

                tmp[0] = txtZahl1.Text;
                tmp[1] = cbOperator.Text;
                tmp[2] = txtZahl2.Text;

                /*if(isNum){
                    Console.WriteLine("ERROR");
                }*/
           

                    /*If(Int32.TryParse(x, out y))*/
                /*else{*//*
                    zahl1 = Convert.ToDouble(tmp[0]);
                    zahl2 = Convert.ToDouble(tmp[2]);
                    //zeichen = Convert.ToChar(tmp[1]);
                    zeichen = tmp[1];

                    switch (zeichen)
                    {

                        case "+":
                            lErgebnis.Text = Convert.ToString(zahl1 + zahl2);
                            break;
                        case "-":
                            lErgebnis.Text = Convert.ToString(zahl1 - zahl2);
                            break;
                        case "*":
                            lErgebnis.Text = Convert.ToString(zahl1 * zahl2);
                            break;
                        case "/":

                            if (zahl2 == 0)
                            {
                                MessageBox.Show("Division durch NULL! ERROR", "ERROR");
                            }
                            else
                            {
                                lErgebnis.Text = Convert.ToString(zahl1 / zahl2);
                            }
                            break;
                        case "%":
                            lErgebnis.Text = Convert.ToString(zahl1 % zahl2);
                            break;
                    }
                /*}*/


       /* }*/


   /*     private void txtZahl1_KeyDown(object sender, KeyEventArgs e)
        {
            /*Regex objNotNumberPattern = new Regex("([0-9])+");

            if (objNotNumberPattern.IsMatch(e.KeyCode.ToString()) || Char.IsControl((char)e.KeyCode))
            {
                e.SuppressKeyPress = false;
            }
            else
            {
                e.SuppressKeyPress = true;
            }*/
    /*
            if (!(('0' <= e.KeyValue && e.KeyValue <= '9') || e.KeyCode < Keys.Help))
            {
                e.SuppressKeyPress = true;
            }

        }*/

     /*   private void txtZahl2_KeyDown(object sender, KeyEventArgs e)
        {
            if (!(('0' <= e.KeyValue && e.KeyValue <= '9') || e.KeyCode < Keys.Help))
            {
                e.SuppressKeyPress = true;
            }
        }*/

        private void button1_Click(object sender, EventArgs e)
        {
            if(textBox1.Text.IndexOf("+") != -1){
                string[] zahlen = textBox1.Text.Split('+');
                double[] tmp = new double[5];
                tmp[0] = Convert.ToDouble(zahlen[0]);
                tmp[1] = Convert.ToDouble(zahlen[1]);
                tmp[2] = tmp[0] + tmp[1];
                label1.Text = tmp[2].ToString();
            }
            if(textBox1.Text.IndexOf("-") != -1){
                string[] zahlen = textBox1.Text.Split('-');
                double[] tmp = new double[5];
                tmp[0] = Convert.ToDouble(zahlen[0]);
                tmp[1] = Convert.ToDouble(zahlen[1]);
                tmp[2] = tmp[0] - tmp[1];
                label1.Text = tmp[2].ToString();
            }
            if(textBox1.Text.IndexOf("*") != -1){
                string[] zahlen = textBox1.Text.Split('*');
                double[] tmp = new double[5];
                tmp[0] = Convert.ToDouble(zahlen[0]);
                tmp[1] = Convert.ToDouble(zahlen[1]);
                tmp[2] = tmp[0] * tmp[1];
                label1.Text = tmp[2].ToString();
            }
            if (textBox1.Text.IndexOf("/") != -1){
                string[] zahlen = textBox1.Text.Split('/');
                double[] tmp = new double[5];
                tmp[0] = Convert.ToDouble(zahlen[0]);
                tmp[1] = Convert.ToDouble(zahlen[1]);
                tmp[2] = tmp[0] / tmp[1];
                label1.Text = tmp[2].ToString();
            }
            if (textBox1.Text.IndexOf("%") != -1){
                string[] zahlen = textBox1.Text.Split('%');
                double[] tmp = new double[5];
                tmp[0] = Convert.ToDouble(zahlen[0]);
                tmp[1] = Convert.ToDouble(zahlen[1]);
                tmp[2] = tmp[0] % tmp[1];
                label1.Text = tmp[2].ToString();
            }     
        }

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {

                if (textBox1.Text.IndexOf("+") != -1)
                {
                    string[] zahlen = textBox1.Text.Split('+');
                    double[] tmp = new double[5];
                    tmp[0] = Convert.ToDouble(zahlen[0]);
                    tmp[1] = Convert.ToDouble(zahlen[1]);
                    tmp[2] = tmp[0] + tmp[1];
                    label1.Text = "Ergebniss: " + tmp[2].ToString();
                }
                if (textBox1.Text.IndexOf("-") != -1)
                {
                    string[] zahlen = textBox1.Text.Split('-');
                    double[] tmp = new double[5];
                    tmp[0] = Convert.ToDouble(zahlen[0]);
                    tmp[1] = Convert.ToDouble(zahlen[1]);
                    tmp[2] = tmp[0] - tmp[1];
                    label1.Text = "Ergebniss: " + tmp[2].ToString();
                }
                if (textBox1.Text.IndexOf("*") != -1)
                {
                    string[] zahlen = textBox1.Text.Split('*');
                    double[] tmp = new double[5];
                    tmp[0] = Convert.ToDouble(zahlen[0]);
                    tmp[1] = Convert.ToDouble(zahlen[1]);
                    tmp[2] = tmp[0] * tmp[1];
                    label1.Text = "Ergebniss: " + tmp[2].ToString();
                }
                if (textBox1.Text.IndexOf("/") != -1)
                {
                    string[] zahlen = textBox1.Text.Split('/');
                    double[] tmp = new double[5];
                    tmp[0] = Convert.ToDouble(zahlen[0]);
                    tmp[1] = Convert.ToDouble(zahlen[1]);
                    tmp[2] = tmp[0] / tmp[1];
                    label1.Text = "Ergebniss: " + tmp[2].ToString();
                }
                if (textBox1.Text.IndexOf("%") != -1)
                {
                    string[] zahlen = textBox1.Text.Split('%');
                    double[] tmp = new double[5];
                    tmp[0] = Convert.ToDouble(zahlen[0]);
                    tmp[1] = Convert.ToDouble(zahlen[1]);
                    tmp[2] = tmp[0] % tmp[1];
                    label1.Text = "Ergebniss: " + tmp[2].ToString();
                }
            }
        }


    }
}
